import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
var _excluded = ["clauseId"],
    _excluded2 = ["isEdit"],
    _excluded3 = ["clauseId", "dataTenantLevel"];

/**
 * expertService.js - 条目配置 service
 * @date: 2019-01-28
 */
import request from 'utils/request';
import { getPlatformVersionApi, parseParameters } from 'utils/utils';
import { CPAAS_PLATFORM } from 'utils/config';
/**
 *
 * 查询条目配置
 * @export
 * @param {Object} params 查询参数
 * @returns
 */

export function queryClause(_x) {
  return _queryClause.apply(this, arguments);
}
/**
 *
 * 查询条目配置详情
 * @export
 * @param {Object} params 查询参数
 * @returns
 */

function _queryClause() {
  _queryClause = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            param = parseParameters(params);
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause')), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryClause.apply(this, arguments);
}

export function queryClauseDetail(_x2) {
  return _queryClauseDetail.apply(this, arguments);
}
/**
 * 新建 - 条目配置
 * @export
 * @param {Object} params
 * @returns
 */

function _queryClauseDetail() {
  _queryClauseDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            param = parseParameters(params);
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause'), "/details"), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _queryClauseDetail.apply(this, arguments);
}

export function addClause(_x3) {
  return _addClause.apply(this, arguments);
}
/**
 * 更新 - 条目配置
 * @export
 * @param {Object} params
 * @returns
 */

function _addClause() {
  _addClause = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause')), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _addClause.apply(this, arguments);
}

export function updateClause(_x4) {
  return _updateClause.apply(this, arguments);
}
/**
 * 查询卡片 已经分配的租户信息
 * @param {object} params - 带分页信息的查询信息
 * @param {object} params.page - 分页信息
 * @param {object} params.sort - 排序信息
 * @param {string} params.tenantName - 租户名称
 * @param {string} params.registerDateFrom - 注册时间从
 * @param {string} params.registerDateTo - 注册时间至
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard-clause-assign
 * @requestMethod GET
 */

function _updateClause() {
  _updateClause = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause')), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _updateClause.apply(this, arguments);
}

export function cardTenantQueryPage(_x5) {
  return _cardTenantQueryPage.apply(this, arguments);
}
/**
 * 给卡片 分配新的租户
 * @param {Tenant[]} params - 租户信息
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard-clause-assign
 * @requestMethod POST
 */

function _cardTenantQueryPage() {
  _cardTenantQueryPage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params) {
    var param;
    return _regeneratorRuntime.wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            param = parseParameters(params);
            return _context5.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause-assign')), {
              method: 'GET',
              query: param
            }));

          case 2:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5);
  }));
  return _cardTenantQueryPage.apply(this, arguments);
}

export function cardTenantInsert(_x6) {
  return _cardTenantInsert.apply(this, arguments);
}
/**
 * 删除 卡片分配新的租户
 * @param {Tenant[]} params - 租户信息
 * @requestUrl {CPAAS_PLATFORM}/v1/dashboard-clause-assign
 * @requestMethod DELETE
 */

function _cardTenantInsert() {
  _cardTenantInsert = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params) {
    return _regeneratorRuntime.wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            return _context6.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause-assign')), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6);
  }));
  return _cardTenantInsert.apply(this, arguments);
}

export function cardTenantDelete(_x7) {
  return _cardTenantDelete.apply(this, arguments);
}
/**
 * 查询条目配置table
 * @export
 * @param {Object} params 查询参数
 * @returns
 */

function _cardTenantDelete() {
  _cardTenantDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(params) {
    return _regeneratorRuntime.wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            return _context7.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause-assign')), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7);
  }));
  return _cardTenantDelete.apply(this, arguments);
}

export function fetchTable(_x8) {
  return _fetchTable.apply(this, arguments);
}
/**
 * 查询条目配置详情form
 * @export
 * @param {Number} clauseId 条目Id
 * @returns
 */

function _fetchTable() {
  _fetchTable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(params) {
    var clauseId, otherParmams, param;
    return _regeneratorRuntime.wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            clauseId = params.clauseId, otherParmams = _objectWithoutProperties(params, _excluded);
            param = parseParameters(otherParmams);
            return _context8.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-card-clauses'), "/").concat(clauseId), {
              method: 'GET',
              query: param
            }));

          case 3:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8);
  }));
  return _fetchTable.apply(this, arguments);
}

export function fetchHead(_x9) {
  return _fetchHead.apply(this, arguments);
}
/**
 * 查询条目配置详情form
 * @export
 * @param {Object} params 查询参数
 * @returns
 */

function _fetchHead() {
  _fetchHead = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(clauseId) {
    return _regeneratorRuntime.wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            return _context9.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause'), "/details/").concat(clauseId), {
              method: 'GET'
            }));

          case 1:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9);
  }));
  return _fetchHead.apply(this, arguments);
}

export function saveClause(_x10) {
  return _saveClause.apply(this, arguments);
}
/**
 * 删除卡片
 * @export
 * @param {Array} params 查询参数
 * @returns
 */

function _saveClause() {
  _saveClause = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(params) {
    var isEdit, otherParmams;
    return _regeneratorRuntime.wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            isEdit = params.isEdit, otherParmams = _objectWithoutProperties(params, _excluded2);
            return _context10.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-clause')), {
              method: isEdit ? 'PUT' : 'POST',
              body: otherParmams
            }));

          case 2:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10);
  }));
  return _saveClause.apply(this, arguments);
}

export function deleteCard(_x11) {
  return _deleteCard.apply(this, arguments);
}
/**
 * 查询条目配置table
 * 如果是租户级 需要传 clauseLevel="TENANT" 和 clauseId
 * @export
 * @param {Object} params 查询参数
 * @returns
 */

function _deleteCard() {
  _deleteCard = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(params) {
    return _regeneratorRuntime.wrap(function _callee11$(_context11) {
      while (1) {
        switch (_context11.prev = _context11.next) {
          case 0:
            return _context11.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard-card-clauses')), {
              method: 'DELETE',
              body: params
            }));

          case 1:
          case "end":
            return _context11.stop();
        }
      }
    }, _callee11);
  }));
  return _deleteCard.apply(this, arguments);
}

export function fetchCard(_x12) {
  return _fetchCard.apply(this, arguments);
}

function _fetchCard() {
  _fetchCard = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(params) {
    var clauseId, dataTenantLevel, newParams, param, newParam;
    return _regeneratorRuntime.wrap(function _callee12$(_context12) {
      while (1) {
        switch (_context12.prev = _context12.next) {
          case 0:
            clauseId = params.clauseId, dataTenantLevel = params.dataTenantLevel, newParams = _objectWithoutProperties(params, _excluded3);
            param = parseParameters(newParams);
            newParam = dataTenantLevel === 'TENANT' ? _objectSpread(_objectSpread({}, param), {}, {
              clauseId: clauseId,
              clauseLevel: 'TENANT'
            }) : param;
            return _context12.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(getPlatformVersionApi('dashboard/card/assign-list')), {
              method: 'GET',
              query: newParam
            }));

          case 4:
          case "end":
            return _context12.stop();
        }
      }
    }, _callee12);
  }));
  return _fetchCard.apply(this, arguments);
}